from multiprocessing import Process
import os

filename = "404.jpg"
size = os.path.getsize(filename)

# 复制上半部分
def top():
    fr = open(filename,'rb')
    fw = open("top.jpg",'wb')
    n = size // 2 # 一半字节数
    while n >= 1024:
        fw.write(fr.read(1024))
        n -= 1024
    fw.write(fr.read(n)) # 复制剩下的
    fr.close()
    fw.close()

def bot():
    fr = open(filename,'rb')
    fw = open("bot.jpg",'wb')
    fr.seek(size // 2) # 文件偏移到中间
    while True:
        data = fr.read(1024)
        if not data:
            break
        fw.write(data)
    fr.close()
    fw.close()

def main():
    p = Process(target=top) # 子进程上半部分
    p.start()
    bot() # 下半部分

if __name__ == '__main__':
    main()

